<#import "/spring.ftl" as s>
<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <title>任务开关配置 - 员工管理系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
<#include '../include/baselink.ftl'>
    <link rel="stylesheet" type="text/css" href="<@s.url '/assets/css/jquery.pagination.css'/>">
    <style>
        .item a {
            text-decoration: none;
        }

        .item a:hover {
            text-decoration: none;
        }
    </style>
</head>

<body class="dashboard-page">
<#include '../include/skin-toolbox.ftl'>
<!-- Start: Main -->
<div id="main">
<#include '../include/header.ftl'>
<#include '../include/sidebar.ftl'>
    <!-- Start: Content-Wrapper -->
    <section id="content_wrapper">
        <!-- Begin: Content -->
        <section id="content" class="table-layout animated fadeIn">

            <!-- begin: .tray-center -->
            <div class="tray tray-center">
                <div class="panel" id="spy7">
                    <div class="panel-heading">
                        <span class="panel-icon"><i class="fa fa-table"></i></span>
                        <span class="panel-title">回调事件查询</span>
                        <span class="panel-controls">
                            <a href="#" class="panel-control-color"></a>
                            <a href="#" class="panel-control-collapse"></a>
                            <a href="#" class="panel-control-fullscreen"></a>
                        </span>
                    </div>

                    <div class="panel-body pn">
                        <div class="bs-component">
                            <div class="table-responsive">
                                <table class="table table-striped table-responsive table-bordered">
                                    <tbody>
                                        <tr>
                                            <th>开关配置:</th>
                                            <td>
                                                <label class="checkbox-inline mr10">
                                                    <input type="checkbox" id="department" v-bind:value="taskConf.department" v-model="taskConf.department">department
                                                </label>
                                                <label class="checkbox-inline mr10">
                                                    <input type="checkbox" id="channel" v-bind:value="taskConf.channel" v-model="taskConf.channel">channel
                                                </label>
                                                <label class="checkbox-inline mr10">
                                                    <input type="checkbox" id="user" v-bind:value="taskConf.user" v-model="taskConf.user">user
                                                </label>
                                                <label class="checkbox-inline mr10">
                                                    <input type="checkbox" id="product" v-bind:value="taskConf.product" v-model="taskConf.product">product
                                                </label>
                                                <label class="checkbox-inline mr10">
                                                    <input type="checkbox" id="customerOrder" v-bind:value="taskConf.customerOrder" v-model="taskConf.customerOrder">customerOrder
                                                </label>

                                                <label class="checkbox-inline mr10">
                                                    <input type="checkbox" id="revisitLog" v-bind:value="taskConf.revisitLog" v-model="taskConf.revisitLog">revisitLog
                                                </label>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>

                    <div class="panel-footer">
                        <button type="button" class="btn btn-primary" v-on:click="findTasks">刷新钉钉注册事件</button>

                        <#--<button type="button" class="btn btn-primary" v-on:click="registerEvent">注册钉钉回调事件</button>-->
                        <#--<button type="button" class="btn btn-primary" v-on:click="deleteEvent">删除钉钉回调事件</button>-->
                        <#--<button id="btnSubmit" type="button" class="btn btn-primary" >测试发起请求</button>-->
                        <#--<button type="button" class="btn btn-primary" v-on:click="syncDepartment()">从企业微信同步部门信息</button>-->
                        <#--<button type="button" class="btn btn-primary" v-on:click="syncUser()">从企业微信同步员工信息</button>-->
                    </div>
                </div>

            </div>
        </section>
        <!-- End: Content -->

    <#include '../include/footer.ftl' />
    </section>
</div>
<#include '../include/footer_js.ftl'/>

<script>
    var app = new Vue({
        el: '#main',
        data: {
            taskConf: {
                department: true,
                channel: false,
                user: false,
                product: false,
                customerOrder: false,
                revisitLog: false
            },
            init: true
        },
        created: function () {
            this.findTasks();
        },
        watch: {
            'taskConf.department': function(){
                this.taskSwitch('department', this.taskConf.department);
            },
            'taskConf.channel': function(){
                this.taskSwitch('channel', this.taskConf.channel);
            },
            'taskConf.user': function(){
                this.taskSwitch('user', this.taskConf.user);
            },
            'taskConf.product': function(){
                this.taskSwitch('product', this.taskConf.product);
            },
            'taskConf.customerOrder': function(){
                this.taskSwitch('customerOrder', this.taskConf.customerOrder);
            },
            'taskConf.revisitLog': function(){
                this.taskSwitch('revisitLog', this.taskConf.revisitLog);
            }
        },
        methods: {
            findTasks: function(){
                this.$http.get(contentPath + "/api/view/jobs/switch/get").then(
                        function (response) {
                            console.log(response);
                            if (response.data.retcode == 2000000) {
                                this.taskConf = response.data.data;
                            } else {
                                toastr.error("设置失败," + response.data.msg, "设置结果");
                            }
                        }, function (error) {
                            toastr.error("设置失败," + error.body.msg, "设置结果");
                        }
                )
            },
            taskSwitch: function(key, value) {
                var url = contentPath + "/api/view/jobs/switch/set?job=" + key + "&runnable=" + value;
                this.$http.get(url).then(
                        function (response) {
                            console.log(response);
                            if (response.data.retcode == 2000000) {
                                toastr.success("设置成功", "设置结果");
                            } else {
                                toastr.error("设置失败," + response.data.msg, "设置结果");
                            }
                        }, function (error) {
                            toastr.error("设置失败," + error.body.msg, "设置结果");
                        }
                )
            }
        }
    });

</script>
</body>
</html>